package top.jandmla.excel.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.jandmla.excel.pojo.QueryPageDTO;
import top.jandmla.excel.bean.Test;
import top.jandmla.excel.dao.TestMapper;
import top.jandmla.excel.service.TestService;


@Service
public class TestServiceImpl extends ServiceImpl<TestMapper, Test> implements TestService {

    @Autowired
    private TestMapper testMapper;

    @Override
    public IPage<Test> selectPageAndTest(QueryPageDTO<Test> dto) {
        Test query = dto.getQuery();

        //不存在条件则全部查询
        QueryWrapper<Test> qw = new QueryWrapper<>();

        //判断条件中是否存在表ID
        if (!StringUtils.isEmpty(query.getNameid())) {
            qw.eq("nameid", query.getNameid());
        }

        //判断条件中是否存在Test数据ID
        if (!StringUtils.isEmpty(query.getId())) {
            qw.eq("id", query.getId());
        }

        //判断条件中是否存在Test数据Name
        if (!StringUtils.isEmpty(query.getName())) {
            qw.like("name", query.getName());
        }

        //判断条件中是否存在Phone
        if (!StringUtils.isEmpty(query.getPhone())) {
            qw.like("phone", query.getPhone());
        }

        //判断条件中是否存在Email
        if (!StringUtils.isEmpty(query.getEmail())) {
            qw.like("email", query.getEmail());
        }

        return testMapper.selectPage(dto.getPage(), qw);
    }

}
